import json
from script.get_contest_info.tools.vj_get_contest_uid import get_user_id
# 返回两个值表示 uid 在 contest_id 竞赛中通过的题目数量和通过题目的最短时间之和
def vj_ac_and_time(contest_id,uid):
    uid = get_user_id(contest_id,uid)

    from script.get_contest_info.response.vj_response import vj_response
    data = json.loads(vj_response(contest_id))
    submissions = data['submissions']

    # 用于存储每道题通过的最小时间
    min_time_dict = {}

    for sub in submissions:
        if str(sub[0]) == str(uid) and sub[2] == 1:  # 如果是指定用户且通过
            problem_id = sub[1]
            time = sub[3]
            if problem_id not in min_time_dict:
                min_time_dict[problem_id] = time
            else:
                min_time_dict[problem_id] = min(min_time_dict[problem_id], time)



    # 计算通过的题目数量和通过题目的最短时间之和
    passed_count = len(min_time_dict)
    total_min_time = sum(min_time_dict.values())

    return passed_count, total_min_time


# 示例调用
if __name__ == "__main__":
    uid = "winterl"  # 这里替换为你要查询的用户uid
    contest_id = 648764  # 这里替换为你要查询的竞赛id
    passed_count, total_min_time = vj_ac_and_time(contest_id,uid)
    print(f"一共通过了 {passed_count} 道题")
    print(f"通过题目的最短时间之和为 {total_min_time}")